<?php
/**
 * 零起飞-(07FLY-CRM)
 * ==============================================
 * 版权所有 2015-2028   成都零起飞网络，并保留所有权利。
 * 网站地址: http://www.07fly.xyz
 * ----------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
 * ==============================================
 * Author: kfrs <goodkfrs@QQ.com> 574249366
 * Date: 2025-03-06 14:34:45
 */

use app\admin\logic\Log as LogicLog;

/**
 * 记录行为日志
 */
function action_log($name = '', $describe = '')
{

	$logLogic = get_sington_object('logLogic', LogicLog::class);

	$logLogic->logAdd($name, $describe);
}
//得到把列表数据=》数形参数
if (!function_exists("list2tree")) {

	function list2tree($list, $pId = 0, $level = 0, $pk = 'id', $pidk = 'pid', $name = 'name')
	{
		$tree = [];
		foreach ($list as $k => $v) {
			if ($v[$pidk] == $pId) { //父亲找到儿子
				$v['nodes'] = list2tree($list, $v[$pk], $level + 1, $pk, $pidk, $name);
				$v['children'] = list2tree($list, $v[$pk], $level + 1, $pk, $pidk, $name);
				$v['level'] = $level + 1;
				$v['treename'] = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level) . '|--' . $v[$name];
				$v['tags'] = $v['id'];
				$v['value'] = $v['id'];
				$v['text'] = $v[$name].'['.$v['id'].']';
				$tree[] = $v;
			}
		}
		return $tree;
	}
}

if (!function_exists("list2tree2menu")) {

	//得到把列表数据=》数形参数
	//导出为菜单格式
	function list2tree2menu($list, $pId = 0, $pk = 'id', $pidk = 'pid', $name = 'name')
	{
		$tree = [];
		$tmp=[];
		foreach ($list as $k => $v) {
			if ($v[$pidk] == $pId) { //父亲找到儿子
				$tmp['name']=$v['name'];
				$tmp['sort']=$v['sort'];
				$tmp['module']=$v['module'];
				$tmp['url']=$v['url'];
				$tmp['visible']=$v['visible'];
				$tmp['is_shortcut']=$v['is_shortcut'];
				$tmp['is_menu']=$v['is_menu'];
				$tmp['icon']=$v['icon'];
				$tmp['url']=$v['url'];
				$tmp['nodes'] = list2tree2menu($list, $v[$pk], $pk, $pidk, $name);
				$tree[] = $tmp;
			}
		}
		return $tree;
	}
}

if (!function_exists("list2select")) {

	/**r把列表数据转为树形下拉
	 * @param $list
	 * @param int $pId
	 * @param int $level
	 * @param string $pk
	 * @param string $pidk
	 * @param string $name
	 * @return array|string
	 * Author: lingqifei created by at 2020/4/1 0001
	 */
	function list2select($list, $pId = 0, $level = 0, $pk = 'id', $pidk = 'pid', $name = 'name',$data=[])
	{
		foreach ($list as $k => $v) {
			$v['treename'] = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level) . '|--' . $v[$name];
			if ($v[$pidk] == $pId) { //父亲找到儿子
				$data[] =$v;
				$data   = list2select($list, $v[$pk], $level + 1, $pk, $pidk, $name,$data);
			}
		}
		return $data;
	}
}
if (!function_exists('isJson')) {

	/**
	 * 判断字符串是否为 Json 格式
	 *
	 * @param string $data Json 字符串
	 * @param bool $assoc 是否返回关联数组。默认返回对象
	 *
	 * @return array|bool|object 成功返回转换后的对象或数组，失败返回 false
	 */
	function isJson($data = '', $assoc = false)
	{
		$data = json_decode($data, $assoc);
		if (($data && is_object($data)) || (is_array($data) && !empty($data))) {
			return $data;
		}
		return false;
	}
}

if (!function_exists('gender_text_en')) {
	function gender_text_en($gender)
	{
		$text = '';
		if ($gender == '1') {
			$text = 'M';
		} else if ($gender == '2') {
			$text = 'F';
		} else {
			$text = 'unknow';
		}
		return $text;
	}
}
?>
